package com.zhz.common.tool.mybatisplus.base.core.contract;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * 基础查询条件
 * @author zhouhengzhe
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class BaseParam implements Serializable {
    private static final long serialVersionUID = -5283460708108514233L;
    /**
     * 当前页码，从1开始，默认1
     */
    protected long page = 1L;
    /**
     * 每页显示记录数, 默认10
     */
    protected long limit = 10L;
    /**
     * 排序字段 多字段用,（小写逗号）隔开 驼峰式
     */
    private String orderField;
    /**
     * 是否升序 默认降序
     */
    private boolean asc;

    public BaseParam(long page, long limit) {
        if (page > 1L) {
            this.page = page;
        }

        this.limit = limit;
    }

    public long getStartIndex() {
        return (this.page - 1L) * this.limit;
    }

    public long getEndIndex() {
        return this.getStartIndex() + this.limit;
    }

}